package com.sangeng.controller;

import com.sangeng.domain.dto.UserInfoDTO;
import com.sangeng.domain.vo.Result;
import com.sangeng.domain.vo.UserInfoVO;
import com.sangeng.service.LoginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/user")
@Slf4j
public class LoginController {
    @Resource
    private LoginService loginService;

    /**
     * 用户登录
     */
    @PostMapping("/login")
    public Result<String> login(@RequestBody UserInfoDTO userInfoDTO){
        log.info("用户登录信息为：{}",userInfoDTO);
        String token = loginService.login(userInfoDTO);
        return Result.ok(token);
    }

    /**
     * 用户登出
     */
    @GetMapping("/logout")
    public Result logout(){
        log.info("用户执行退出操作：");
        loginService.logout();
        return Result.ok();
    }

    /**
     * 获取用户信息
     */
    @GetMapping("/info")
    public Result<UserInfoVO> getUserInfo(){
        log.info("获取登录的用户信息:");
        UserInfoVO userInfoVO = loginService.getUserInfo();
        return Result.ok(userInfoVO);
    }
}
